package com.sxt.opd.controller;


import com.sxt.opd.vo.PatientVo;
import com.sxt.springcloud.opd.PatientClientService;
import com.sxt.sys.common.DataGridView;
import com.sxt.sys.common.ResultObj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.WebRequest;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author author
 * @since 2020-01-06
 */
@RestController
@RequestMapping("/patient")
public class PatientController {


    @Autowired
    private PatientClientService patientClientService;

    /**
     * 前台传日期，后台Date接值类型转换错误
     *
     * @param binder
     * @param request
     */
    @InitBinder
    public void InitBinder(WebDataBinder binder, WebRequest request) {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        CustomDateEditor editor = new CustomDateEditor(df, true);//参数为true表示允许为空值
        binder.registerCustomEditor(Date.class, editor);
    }

    /**
     * 查询
     */
    @RequestMapping("loadAllPatient")
    public DataGridView loadAllPatient(PatientVo patientVo) {
        return this.patientClientService.loadAllPatient(patientVo);
    }

    /**
     * 添加
     */
    @RequestMapping("addPatient")
    public ResultObj addPatient(PatientVo patientVo) {
        return this.patientClientService.addPatient(patientVo);
    }

    /**
     * 修改
     */
    @RequestMapping("updatePatient")
    public ResultObj updatePatient(PatientVo patientVo) {
        return this.patientClientService.updatePatient(patientVo);
    }

    /**
     * 删除
     */
    @RequestMapping("deletePatient")
    public ResultObj deletePatient(Integer id) {
        return this.patientClientService.deletePatient(id);
    }

    /**
     * 批量删除
     */
    @RequestMapping("batchDeletePatient")
    public ResultObj batchDeletePatient(PatientVo patientVo) {
        return this.patientClientService.batchDeletePatient(patientVo);
    }

    /**
     * 根据供应商ID查询商品信息
     */
    @RequestMapping("loadPatientById")
    public DataGridView loadPatientById(Integer id) {
        return this.patientClientService.loadPatientById(id);
    }


}

